﻿using PlayListSet.Comm;
using PlayListSet.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PlayListSet.UI
{
    /// <summary>
    /// PlayInfoItem.xaml 的交互逻辑
    /// </summary>
    public partial class PlayCmdItem : UserControl, IPlayInfo
    {
        public PlayCmd PlayCmd { set; get; }
        public event DeleteItem OnDelete;
        public PlayCmdItem()
        {
            InitializeComponent();
            //PlayInfo.PropertyChanged += PlayInfo_PropertyChanged;
            this.Loaded += PlayInfoItem_Loaded;
        }

        private void PlayInfoItem_Loaded(object sender, RoutedEventArgs e)
        {
            this.SetBinding(OpacityProperty, new Binding("Opacity") { Source = PlayCmd });
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            OnDelete?.Invoke(this, PlayCmd);
        }

        public long GetPlayInfoId()
        {
           return PlayCmd.ID;
        }
 

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            AppControl.Instance.CopySelect = PlayCmd;
        }

        private void copy_click(object sender, RoutedEventArgs e)
        {
            try
            {
                 AppHelp.CopyToClipboard(new AppHelp.ATSCopyClipboardData() { CopyType = AppHelp.CopyType.PlayCmd, Data = PlayCmd });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            AppControl.Instance.CopySelect = null;
        }

        private void UserControl_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            ContextMenu contextMenu = new ContextMenu();
            var c = new MenuItem { Header = "复制" };
            c.Click += copy_click;

            contextMenu.Items.Add(c);
            var d = new MenuItem { Header = "删除" };
            d.Click += MenuItem_Click;

            contextMenu.Items.Add(d);
            this.ContextMenu = contextMenu;
            this.ContextMenu.IsOpen = true;
        }

        //private void PlayInfo_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        //{

        //}
    }
}
